package fzdy.tools;


import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2018/1/9 0009.
 */
public class TimeStampTool {
    public static String timeStampToString(String pattern, Timestamp time){
        DateFormat format = new SimpleDateFormat(pattern);
        return format.format(time);
    }
    public static Timestamp StringTotimeStamp(String pattern, String time){
        DateFormat format = new SimpleDateFormat(pattern);
        try {
            return new Timestamp(format.parse(time).getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String DateToString(String pattern, Date time){
        DateFormat format = new SimpleDateFormat(pattern);
        return format.format(time);
    }
    public static Date StringToDate(String pattern, String time){
        DateFormat format = new SimpleDateFormat(pattern);
        try {
            return format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
